From 17ffbf8bde5acb6e7af6a8112e241f9c252f41e2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 2 Apr 2015 11:51:29 -0700 Subject: [PATCH] Be sure to include dev-deps for doctests with --extern Previously the "add immediate deps" logic bailed out too soon and didn't pick up all dev-dependencies. Closes #1474 --- src/cargo/ops/cargo_rustc/mod.rs | 32 ++++++++++++++++---------------- tests/test_cargo_test.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 0415a9c7c..d8d14820c 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -143,23 +143,23 @@ pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)], let pkgid = pkg.package_id().clone(); cx.compilation.libraries.entry(pkgid).or_insert(Vec::new()) .push((target.crate_name(), dst)); - if !target.is_lib() { continue } + } + if !target.is_lib() { continue } - // Include immediate lib deps as well - for dep in cx.dep_targets(pkg, target, profile).iter() { - let (pkg, target, profile) = *dep; - let pkgid = pkg.package_id(); - if !target.is_lib() { continue } - if profile.doc { continue } - if cx.compilation.libraries.contains_key(&pkgid) { continue } - - let v = try!(cx.target_filenames(target, profile)); - let v = v.into_iter().map(|f| { - (target.crate_name(), - cx.out_dir(pkg, Kind::Target, target).join(f)) - }).collect::>(); - cx.compilation.libraries.insert(pkgid.clone(), v); - } + // Include immediate lib deps as well + for dep in cx.dep_targets(pkg, target, profile).iter() { + let (pkg, target, profile) = *dep; + let pkgid = pkg.package_id(); + if !target.is_lib() { continue } + if profile.doc { continue } + if cx.compilation.libraries.contains_key(&pkgid) { continue } + + let v = try!(cx.target_filenames(target, profile)); + let v = v.into_iter().map(|f| { + (target.crate_name(), + cx.out_dir(pkg, Kind::Target, target).join(f)) + }).collect::>(); + cx.compilation.libraries.insert(pkgid.clone(), v); } } } diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 6cf457aee..eb129202f 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -1419,3 +1419,32 @@ test!(dashes_to_underscores { assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0)); }); + +test!(doctest_dev_dep { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dev-dependencies] + b = { path = "b" } + "#) + .file("src/lib.rs", r#" + /// ``` + /// extern crate b; + /// ``` + pub fn foo() {} + "#) + .file("b/Cargo.toml", r#" + [package] + name = "b" + version = "0.0.1" + authors = [] + "#) + .file("b/src/lib.rs", ""); + + assert_that(p.cargo_process("test").arg("-v"), + execs().with_status(0)); +}); -- 2.30.2